import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 动态路由表，需要权限才能访问
import departments from '../router/modules/departments'
import employees from '../router/modules/employees'
import settings from '../router/modules/settings '
import salarys from '../router/modules/salarys '
import socials from '../router/modules/social'
import attendances from '../router/modules/attendances'
import approvals from '../router/modules/approvals'
import permission from '../router/modules/permission'
// import permission from '../router/modules/permission'

// import employees from '../router/modules/employees'

// 如果想要路由不在左侧菜单上显示，就设置 hidden=true
export const asyncRoutes = [
  departments,
  settings,
  employees,
  permission,
  approvals,
  attendances,
  salarys,
  socials

  // permission

]

// 静态路由表，不需要权限就能访问
export const constantRoutes = [
  {
    path: '/import',
    component: () => import(/* webpackChunkName:"import"*/'@/views/import/index.vue'),
    hidden: true
  },
  // {
  //   path: '/deom',
  //   component: () => import('@/views/demo/fath'),
  //   hidden: true
  // },

  {
    path: '/login',
    component: () => import(/* webpackChunkName:"login"*/'@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import(/* webpackChunkName:"dashboard"*/'@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes] // 将动态路由和静态路由，合并成最终的路由表
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
